class Solution {
    public int[] searchRange(int[] nums, int target) {
        int l=0, r=nums.length-1;
        int n1 = -1;
        // n1为第一个等于target的数
        while( l<=r ){
            int mid = (l+r)/2;
            if( nums[mid]<target ){
                l = mid+1;
            }else{
                r = mid-1;
                n1 = mid;
            }
        }
        l=0; r=nums.length-1;
        // n2为最后一个等于target的数
        int n2 = -1;
        while( l<=r ){
            int mid = (l+r)/2;
            if( nums[mid]<=target ){
                l = mid+1;
                n2 = mid;
            }else{
                r = mid-1;
            }
        }
        if(n1==-1 || nums[n1]!=target)
            return new int[]{-1,-1};

        return new int[]{n1,n2}; 
    }
}